// pages/index/productD/productD.js
const app = getApp();
import request from '../../../utils/http.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    left: 0,

    scrollFlag: false,


    fuWuBaoOrderFormId: 0, //产品id
    chanPinMingCheng: '', //产品名称
    tuPianUrl: '', //产品封面

    shiJiJiaGe: 0, //实际销售价格
    gouMaiRen:'',

    zhiFuRiQiStr:'',
    jinDu:'',
    chanPinZhongLei:0,
    chanPinZongJianShu:'',
    fuWuXiangMuZongShu:0,
    zengSongShu:0,


    yiShengList: [],
    yiShengListlength: 0,
    zhongXinChanPinList:[],
    xianXiaXiangMuList:[],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    var that = this


    that.setData({
      fuWuBaoOrderFormId: options.fuWuBaoOrderFormId, 
    })


    that.getProductDetail();

    var that = this
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          screenHeight: res.screenHeight,
          width: res.screenWidth
        })
      }
    })
  },



  //获取产品详情
  getProductDetail: function () {
    var that = this
    wx.showLoading({
      title: '加载中...',
      mask: true
    })
    let data = {
      fuWuBaoOrderFormId: that.data.fuWuBaoOrderFormId,

    }
    request.get('fuWuBaoOrderForm/orderFormDetail', data, res => {

      console.log("服务包详情:" + JSON.stringify(res.data))

      that.setData({
        chanPinMingCheng: res.data.mingCheng,
        tuPianUrl: res.data.productBeiJingTuUrl,
        shiJiJiaGe: res.data.gouMaiJiaGe,
        yiShengList: res.data.yiShengList,
        yiShengListlength: res.data.yiShengList.length,
        gouMaiRen:res.data.gouMaiRen,
        zhiFuRiQiStr:res.data.zhiFuRiQiStr,
        jinDu:res.data.jinDu,
        fuWuXiangMuZongShu:res.data.fuWuXiangMuZongShu,
        chanPinZhongLei:res.data.chanPinZhongLei,
        zengSongShu:res.data.zhongXinChanPinList.length-res.data.chanPinZhongLei,

        chanPinZongJianShu:res.data.chanPinZongJianShu,
        zhongXinChanPinList: res.data.zhongXinChanPinList,
        xianXiaXiangMuList:res.data.xianXiaXiangMuList,
      })




      wx.hideLoading();
    }, err => {
      wx.hideLoading();
      wx.showToast({
        title: '查询失败！', // 提示的内容
        icon: "none", // 图标，默认success
        duration: 1000, // 提示的延迟时间，默认1500
        mask: false, // 是否显示透明蒙层，防止触摸穿透
      })
    })

  },


  // 关闭分享弹框
  colseShare: function () {
    this.setData({
      shareble: false,
      bottomViewble: false,

    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    // 获取swipre高度，设置店铺信息和菜单固定位置

    if (this.data.IsLogin) {
      wx.showShareMenu({
        menus: ['shareAppMessage', 'shareTimeline']
      })

      this.getJZPerson();

    } else {
      wx.hideShareMenu({
        menus: ['shareAppMessage', 'shareTimeline']
      })
    }

    // this.getProductDetail(); // 刷新购物车
  },




  //分享产品
  onShareAppMessage: function (res) {
    var that = this;
    that.setData({
      shareble: false
    })

    if (that.data.IsLogin) {
      return {
        title: that.data.chanPinMingCheng,
        path: '/pages/productInfo/productInfo?dianPuId=' + that.data.dianPuId + '&&productId=' + that.data.productId + '&&tjr_id=' + that.data.personId,
        imageUrl: that.data.tuPianUrl
      }
    } else {
      wx.showToast({
        title: '请先登录！', // 提示的内容
        icon: "none", // 图标，默认success
        duration: 1000, // 提示的延迟时间，默认1500
        mask: false, // 是否显示透明蒙层，防止触摸穿透
      })
    }
  },




  //圖片滑动监控
  scrolltolower: function () {
    this.setData({
      scrollFlag: true
    })
  },

  scrolltoupper: function () {
    this.setData({
      scrollFlag: false
    })
  },


})